package cc.gpai.util.slotboard;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class CustomSlot implements Slot {
	private String name;
	private Map<Method,Object> map = new HashMap<Method,Object>();
	
	public CustomSlot() {
		this(String.valueOf(SlotBoard.rand.nextLong()));
	}

	public CustomSlot(String name) {
		super();
		setName(name);
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		SlotBoard.updateName(this.name, name, this);
		this.name = name;
	}

	public Object put(Method key, Object value) {
		return map.put(key, value);
	}

	public void clear() {
		map.clear();
	}

	@Override
	public Object receiveSignal(SignalEvent e) {
		try {
			Object obj = map.get(e.method);
			return e.method.invoke(obj, e.args);
		} catch (Exception x) {
			return null;
		}
	}

}
